package Lib3d.Scenes;


import Lib3d.Vector3d;
import Lib3d.Animation.Animation;
import Lib3d.Animation.AnimationFactory;
import Lib3d.PresetModel3d.Sphere;
import Lib3d.SceneGraph.Group;
import Lib3d.SceneGraph.Node;
import Lib3d.SceneGraph.Impl.AnimatedGroupImpl;
import Lib3d.SceneGraph.Impl.GroupImpl;
import Lib3d.SceneGraph.Impl.RotationImpl;
import Lib3d.SceneGraph.Impl.TranslationImpl;

import java.awt.Color;
import java.util.Iterator;

import javax.media.opengl.GLAutoDrawable;

/**
 * A implementation of a simple shpere scene (with one simple shpere - with no
 * hairs!).
 * 
 * @author Wassim Chegham
 * @version 0.1
 * @category Lib3d.Scenes
 * 
 */
public class SceneSimpleSphereImpl implements Scene {

    final Group tmpRoot = new GroupImpl();

    public void addChild(final Node child) {
        this.tmpRoot.addChild(child);
    }

    public Iterator<Node> childIterator() {
        // TODO Auto-generated method stub
        return null;
    }

    public Node draw() {

        final Sphere sphere1 = new Sphere(Color.GREEN);
        final Sphere sphere2 = new Sphere(Color.RED);
        final Sphere sphere3 = new Sphere(Color.BLUE);
        sphere2.setRadius(50);
        sphere3.setRadius(25);

        // sphere 1
        final AnimatedGroupImpl agr1 = new AnimatedGroupImpl();
        final Animation anim1 = AnimationFactory.createSimpleAnimation();
        anim1.setSpeed(0.1f);
        anim1.setDistance(10);
        anim1.setRotation(new Vector3d(0, 1, 0), 45f); // not working for now !!
        agr1.addAnimation(anim1);
        agr1.addChild(sphere1);

        // sphere 2
        final AnimatedGroupImpl agr2 = new AnimatedGroupImpl();
        final Animation anim2 = AnimationFactory.createBezierAnimation();
        anim2.setSpeed(0.02f);
        anim2.setDistance(400f);
        agr2.addChild(sphere2);
        agr2.addAnimation(anim2);

        // sphere 3
        final AnimatedGroupImpl agr3 = new AnimatedGroupImpl();
        final Animation anim3 = AnimationFactory.createBezierAnimation();
        anim3.setSpeed(0.05f);
        anim3.setDistance(100f);
        agr3.addChild(sphere3);
        agr3.addAnimation(anim3);

        // root
        final Group maman = new TranslationImpl(new Vector3d(0, 0, 0));
        maman.addChild(agr1);
        maman.addChild(agr2);
        maman.addChild(agr3);

        // rotate the rotate
        final Group rot1 = new RotationImpl(new Vector3d(1, 0, 0), 10f);
        rot1.addChild(maman);
        return rot1;
    }

    public void draw(final GLAutoDrawable gLDrawable) {
        this.tmpRoot.draw(gLDrawable);
    }

}
